package weixin.app.wx.service.rest.util;

import java.util.UUID;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import weixin.app.WXServiceAppFactoryDemo;
import weixin.app.wx.service.rest.entities.Signature;
import weixin.app.wx.service.rest.util.aes.SHA1;

@SuppressWarnings("all")
public class SignatureGenerator {
  public static Signature generate(final String url) {
    Signature _xblockexpression = null;
    {
      final String ticket = WXServiceAppFactoryDemo.getServiceApp().getTicket();
      long _currentTimeMillis = System.currentTimeMillis();
      long _divide = (_currentTimeMillis / 1000);
      final String timeStamp = String.valueOf(_divide);
      final String nonceStr = UUID.randomUUID().toString().replace("-", "").substring(0, 16);
      InputOutput.<String>println(((((("=====>ticket:" + ticket) + "; timeStamp: ") + timeStamp) + "; nonceStr: ") + nonceStr));
      Signature _signature = new Signature();
      final Procedure1<Signature> _function = (Signature it) -> {
        try {
          it.setSignature(SHA1.getSHA1(("jsapi_ticket=" + ticket), ("timestamp=" + timeStamp), ("noncestr=" + nonceStr), ("url=" + url)));
          it.setNonceStr(nonceStr);
          it.setTimestamp(timeStamp);
          it.setAppid("wx01ad0d700af56f26");
        } catch (Throwable _e) {
          throw Exceptions.sneakyThrow(_e);
        }
      };
      _xblockexpression = ObjectExtensions.<Signature>operator_doubleArrow(_signature, _function);
    }
    return _xblockexpression;
  }
}
